<?php
/**
 * Created by PhpStorm.
 * User: asdf
 * Date: 2021/9/24
 * Time: 1:17
 */
namespace core\lib;

use function core\p;

class Config{

    static public $conf = [];



    static public function get($file,$name,$lastfix = ".php"){
        if (isset(self::$conf[$file][$name])){
            return self::$conf[$file][$name];
        }else{
            $file = CONFIG.Dirp.$file.$lastfix;
            if (is_file($file)){
                $config = include $file;
                if (isset($config[$name])){
                    self::$conf[$file] = $config;
                    return $config[$name];
                }else{
                    throw new \ErrorException("no such option");
                }
            }else{
                throw new \ErrorException("no such file");
            }
        }

    }


    static public function all($file,$lastfix = ".php"){
        if (isset(self::$conf[$file])){
            return self::$conf[$file];
        }else{
            $file = CONFIG.Dirp.$file.$lastfix;
            if (is_file($file)){
                $config = include $file;
                self::$conf[$file] = $config;
                return $config;
            }else{
                throw new Exception("no such file");
            }
        }
    }
}